﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MESCodeFile;

namespace mes_tublay
{
    public partial class frmMain : Form
    {
        
        public frmMain()
        {
            InitializeComponent();
            //InitializeLiveNotification();

            this.Resize += new EventHandler(frmMain_Resize);
            this.FormClosing += new FormClosingEventHandler(frmMain_FormClosing);
            this.Load += new EventHandler(frmMain_Load);
            sldMain.ItemRemoved += new EventHandler(sldMain_ItemRemoved);
            sldMain.ItemAdded += new EventHandler(sldMain_ItemAdded);
            sldMain.AnimationCompleted += new EventHandler(sldMain_AnimationCompleted);
            
            //Clean up for the Main Form contructor.
            MenuHandlers();
        }

        void frmMain_Load(object sender, EventArgs e)
        {
            Common.PARENT = this;
            LoadSettings();
        }
        void LoadSettings()
        {
            frmConfig frm = new frmConfig();
            frm.Initialize("SETTINGS");
        }

        #region FrameSliderForm
        void mnuExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (sldMain.ItemCount > 0)
            {
                string msg = string.Format("There are {0} session(s) running. Are you sure to close the application?", sldMain.ItemCount);
                DialogResult dlg = MessageBox.Show(msg, "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (dlg == DialogResult.No) e.Cancel = true;
            }
        }
        void frmMain_Resize(object sender, EventArgs e)
        {
            sldMain.Width = this.Width - 40;
            sldMain.Height = this.Height - 77 - 25;
            liveNotify.Width = sldMain.Width;
            liveNotify.NotifyOpenHeight = sldMain.Height;
        }
        void sldMain_ItemRemoved(object sender, EventArgs e)
        {
            string[] buf = sldMain.ItemList;
            mnuWindow.DropDownItems.Clear();
            for (int i = 0; i < buf.Length; i++)
            {
                mnuWindow.DropDownItems.Add((i + 1) + "-" + buf[i], null, new EventHandler(window_Click));
                mnuWindow.DropDownItems[i].ForeColor = Color.Black;
            }
            if (sldMain.ItemCount > 0) mnuWindow.DropDownItems[sldMain.SelectedIndex].ForeColor = Color.RoyalBlue;
            mnuCloseAll.Text = "Close All Sessions (" + buf.Length + ")";
        }
        void sldMain_ItemAdded(object sender, EventArgs e)
        {
            string[] buf = sldMain.ItemList;
            mnuWindow.DropDownItems.Clear();
            for (int i = 0; i < buf.Length; i++)
            {
                mnuWindow.DropDownItems.Add((i + 1) + "-" + buf[i], null, new EventHandler(window_Click));
                mnuWindow.DropDownItems[i].ForeColor = Color.Black;
            }
            mnuWindow.DropDownItems[sldMain.SelectedIndex].ForeColor = Color.RoyalBlue;
            mnuCloseAll.Text = "Close All Sessions (" + buf.Length + ")";
        }
        void sldMain_AnimationCompleted(object sender, EventArgs e)
        {
            for (int i = 0; i < mnuWindow.DropDownItems.Count; i++)
            {
                mnuWindow.DropDownItems[i].ForeColor = Color.Black;
            }
            mnuWindow.DropDownItems[sldMain.SelectedIndex].ForeColor = Color.RoyalBlue;
        }
        void window_Click(object sender, EventArgs e)
        {
            int index = mnuWindow.DropDownItems.IndexOf((ToolStripItem)sender);
            for (int i = 0; i < mnuWindow.DropDownItems.Count; i++)
            {
                mnuWindow.DropDownItems[i].ForeColor = Color.Black;
            }
            sldMain.MoveTo(index);
            mnuWindow.DropDownItems[index].ForeColor = Color.RoyalBlue;
        }
        void mnuCloseAll_Click(object sender, EventArgs e)
        {
            if (Confirm.Question("Close All", "This will close all opened sessions.Do you wish to continue?")
                   == System.Windows.Forms.DialogResult.No) return;
            if (sldMain.ItemCount > 0)
            {
                sldMain.Controls.Clear();
            }
        }
        #endregion

        //load frmApplicationBusinessPermit
        public void viewApplicationFormForBusinessPermit()
        {
            frmApplicationBusinessPermit frms = new frmApplicationBusinessPermit();
            frms.Initialize("Application Form For Business Permit");
            sldMain.AddItem(frms.PanelForm, "Application Form For Business Permit");
        }
        public void viewApplicationFormForBusinessPermit(myParam info)
        {
            frmApplicationBusinessPermit frms = new frmApplicationBusinessPermit(info);
            if (info.action.Equals("ADDITIONAL"))
            {
                frms.Initialize("Additional Business Permit For " + info.myReferenceNumber);
                sldMain.AddItem(frms.PanelForm, "Additional Business Permit For " + info.myReferenceNumber);
            }
            else if (info.action.Equals("RENEWAL"))
            {
                frms.Initialize("Renewal Business Permit For Reference Number: " + info.myReferenceNumber + " and Application Number: " + info.myApplicationNumber);
                sldMain.AddItem(frms.PanelForm, "Renewal Business Permit For Reference Number: " + info.myReferenceNumber + " and Application Number: " + info.myApplicationNumber);
            }
            else if (info.action.Equals("TRANSFER LOCATION"))
            {
                frms.Initialize("Transfer Location For Reference Number: " + info.myReferenceNumber + " and Application Number: " + info.myApplicationNumber);
                sldMain.AddItem(frms.PanelForm, "Transfer Location For Reference Number: " + info.myReferenceNumber + " and Application Number: " + info.myApplicationNumber);
            }
            else if (info.action.Equals("VIEW"))
            {
                frms.Initialize("View Business Permit with Reference Number: " + info.myReferenceNumber + " and Application Number: " + info.myApplicationNumber);
                sldMain.AddItem(frms.PanelForm, "View Business Permit with Reference Number: " + info.myReferenceNumber + " and Application Number: " + info.myApplicationNumber);
            }
            else if (info.action.Equals("TRANSFER OWNERSHIP"))
            {
                frms.Initialize("Transfer Business Ownership of this Application Number: " + info.myApplicationNumber);
                sldMain.AddItem(frms.PanelForm, "Transfer Business Ownership of this Application Number: " + info.myApplicationNumber);
            }
        }

        public void EnableMenu(string frmName)
        {
            switch (frmName)
            {
                case "MAYOR_OFFICE_APPROVAL":
                    mnuMayor.Visible = true;
                    sp.Visible = false;
                    mnuMayorsApprovalForm.Visible = true;
                    mnuClearanceAndReports.Visible = false;
                    mnuSpecialDocumentsChecklist.Visible = false;
                    mnuBusinessPermit.Visible = false;
                    break;

                case "MAYOR_OFFICE":
                    mnuMayor.Visible = true;
                    mnuClearanceAndReports.Visible = true;
                    mnuSpecialDocumentsChecklist.Visible = true;
                    mnuBusinessPermit.Visible = true;
                    mnuMayorsApprovalForm.Visible = false;
                    sp.Visible = true;
                    break;
                
                case "MHO":
                    mnuDocumentCheckList.Visible = true;
                    documentChecklist.responsibleOffice = "MHO";
                    documentChecklist.description = "SANITARY - HEALTH CLEARANCE";
                    break;
                case "MASSO":
                    mnuDocumentCheckList.Visible = true;
                    documentChecklist.responsibleOffice = "MASSO";
                    documentChecklist.description = "MASSO CLEARANCE";
                    break;
                case "MEO":
                    mnuDocumentCheckList.Visible = true;
                    documentChecklist.responsibleOffice = "MEO";
                    documentChecklist.description = "OCCUPATION PERMIT";
                    break;
                case "FIRE_DEPARTMENT":
                    mnuDocumentCheckList.Visible = true;
                    documentChecklist.responsibleOffice = "FIRE_DEPARTMENT";
                    documentChecklist.description = "FIRE SAFETY INSPECTION CERTIFICATE";
                    break;
                case "MPDO":
                    mnuDocumentCheckList.Visible = true;
                    documentChecklist.responsibleOffice = "MPDO";
                    documentChecklist.description = "ZONING CLEARANCE";
                    break;
                
                case "PNP_TUBLAY":
                    mnuDocumentCheckList.Visible = true;
                    documentChecklist.responsibleOffice = "PNP_TUBLAY";
                    documentChecklist.description = "POLICE CLEARANCE";
                    break;
                case "ADMINISTRATOR":
                    mnuAdmin.Visible = true;
                    break;
                
                case "TREASURY_DEPT":
                    mnuTreasuryDept.Visible = true;
                    break;
                case "TREASURY_DEPT_ASSESSMENT":
                    mnuTreasuryDept.Visible = true;
                    mnuschedofvalues.Visible = false;
                    mnuaddbusinesstype.Visible = false;
                    break;
                case "TREASURY_DEPT_TREASURER":
                    mnuTreasuryDept.Visible = true;
                    break;
                case "ASSESSOR_DEPT":
                    mnuAssessorDept.Visible = true;
                    break;
                case "GSO_INVENTORY_MANAGEMENT_MODULE":
                    mnuPropertyCustodian.Visible = true;
                    break;
            }
            if (mnuLogin.Text == "Logout XCODER-ADMINISTRATOR") return;
            mnuProfile.Visible = true;
        }
        public void DisableMenu()
        {
            mnuAdmin.Visible = false;
            mnuMayor.Visible = false;
            sepMayor.Visible = false;
            mnuTreasuryDept.Visible = false;
            mnuAssessorDept.Visible = false;
            mnuProfile.Visible = false;
            mnuDocumentCheckList.Visible = false;
            mnuPropertyCustodian.Visible = false;
        }

        public void SetLoginName(string name)
        {
            mnuLogin.Text = "Logout " + name;
            liveNotify.NotifyTitle = CurrentUser.UID + "'s Notifications";
            liveNotify.NotifyTitleImage = CurrentUser.IMG;
        }
        public void AddForm(Panel frm, string title)
        {
            sldMain.AddItem(frm, title);
        }
    }
}
